<?php /* Smarty version 2.6.20, created on 2012-06-20 16:36:08
         compiled from _core/pagecommon/_mvc/_control/handlepagebackendcontract.tpl */ ?>
function HandlePageBackendContract(gui, operater, now, options) {
  this._gui = gui;
  this._operator = operater;
  this._now = now;
  this._options = options;
  this._createElements();
};

HandlePageBackendContract.prototype._createElements = function() {
  //this._gui.type.disabled = true;
  
  this._loadData();
};

HandlePageBackendContract.prototype._loadData = function() {
  this._contract = null;
  this._retrieveContract();
};

HandlePageBackendContract.prototype._verifyData = function() {
  if (this._contract) {
    this._updateElements();
  }
};

HandlePageBackendContract.prototype._retrieveContract = function() {
  var _self = this;
  if (this._options.id) {
    /*new RequestUtils()._read('contract', null, 'd.oid = ' + this._options.id, null, null, null, null, function(result, params) { _self._contract = (result.data.length == 1) ? result.data[0] : null;
                                                                                                                                 _self._verifyData.call(_self);
                                                                                                                                 }, null);*/
  var args = '&oid=' + this._options.id; 
  new RequestUtils()._mysql('contract', args, function(result, params) { _self._contract = (result.data.length == 1) ? result.data[0] : null;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php'});                                                                                                                               
                                                                                                                               
  } else {
    this._contract = Contract.instance();
    this._verifyData();
  }
};

HandlePageBackendContract.prototype._updateElements = function() {
  var _self = this;
  
  this._gui.type.options[this._gui.type.options.length] = new Option('');
  for (var i = 0, il = OrderType.array().length; i < il; i++) {
    var type = OrderType.array()[i];
    option = new Option(type);
    this._gui.type.options[this._gui.type.length] = option;
    if (option.text == this._contract.orderType) {
      this._gui.type.selectedIndex = this._gui.type.options.length - 1;
    }
  }
  this._gui.type.onchange = function() { _self._contract.orderType = this.options[this.selectedIndex].text; };
  
  this._gui.content.value = this._contract.content;
  this._gui.content.onchange = function() { _self._contract.content = this.value; };
  
  this._gui.save.onclick = function() { var str = '';
                                        if (_self._contract.content == '') {
                                          str += '合同内容,';
                                        }
                                        if (_self._contract.content == '') {
                                          window.alert(str.substring(0, str.length-1) + ' 不能为空');
                                        } else {
                                          new RequestUtils()._mwrite('contract', [_self._contract], [], function() { history.back(); }, null); };
                                        }
  this._gui.cancel.onclick = function() { history.back(); };
};
